<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021-01-14
 * Time: 12:14
 */
namespace app\wdeces\controller;

use smartybuilder\libs\Quickbuilder;
use think\facade\Filesystem;
use think\Request;

class Index
{
    public function index(){
//        $array = explode(',','/storage/20210114/2e844dbdcbdacac7ac67ab0788fb4ab8.png');
        $array = [
          [
              'id'=>'1',
              'name'=>'第一个',
              'child'=>[
                  [
                      'id'=>'3',
                      'name'=>'成都',
                  ]
              ]
          ],
            [
                'id'=>'2',
                'name'=>'第一个1',
                'child'=>[
                    [
                        'id'=>'4',
                        'name'=>'成都1',
                    ]
                ]
            ],
            [
                'id'=>'5',
                'name'=>'第一个2',
                'child'=>[
                    [
                        'id'=>'6',
                        'name'=>'成都2',
                        'child'=>[
                            [
                                'id'=>7,
                                'name'=>'四川'
                            ]
                        ]
                    ]
                ]
            ],
        ];
//        echo '<pre>';
//        print_r($array);
//        exit;
        $options = [
          [
              'id'=>1,
              'name'=>'第一个'
          ],
            [
                'id'=>2,
                'name'=>'第二个'
            ],
        ];
        $option = [
            '第一个',
            '第二个',
        ];
        $tree = [
            [
                'title'=>'江西',
                'id'=>'1',
                'children'=>[
                    [
                        'title'=>'南昌',
                        'id'=>'2',
                        'children'=>[
                            'title'=>'高新区',
                            'id'=>'3',
                        ],
                    ]
                ],
            ],
            [
                'title'=>'陕西',
                'id'=>'4',
                'children'=>[
                    [
                        'title'=>'西安',
                        'id'=>'5',
                    ],
                    [
                        'title'=>'西安1',
                        'id'=>'6',
                    ],
                ]
            ]
        ];
        $jsons = [
          'key'=>[
              '撒地方都是发大',
              '撒地方都是发大1',
              '撒地方都是发大2',
          ],
            'value'=>[
                '是打发的撒范德萨',
                '是打发的撒范德萨1',
                '是打发的撒范德萨2',
            ],
        ];

        return Quickbuilder::make('form')
            ->setAction(url('wdeces/index/haha')->build())
            ->set_up_form('input','名字','name','毛文科','开启,关闭','这是标注')
            ->set_up_form('textarea','多行文本','textarea','多行的文本',[],'多行文本')
            ->set_up_form('none','','textarea','多行的文本')
            ->set_up_form('select','一维下拉框','select1','成功',['成功','失败'],'一维单选框')
            ->set_up_form('select','二维下拉框','select2','0',[['id'=>1,'name'=>'成功'],['id'=>0,'name'=>'失败']],'二维下拉框',2)
//            ->set_up_form('select','一维下拉框','radio1','成功',['成功','失败'],'一维单选框')
            ->set_up_form('radio','二维单选框','radio2','0',[['id'=>1,'name'=>'成功'],['id'=>0,'name'=>'失败']],'二维单选框',2)
            ->set_up_form('editor','编辑框','editor','你好','','编辑器')
            ->set_up_form('img','单图片','img','/storage/20210115/ea8bbf02c6814a7ba1ba5086a9dc17f9.png',[],'单图片')
            ->set_up_form('imgs','多图片','imgs','/storage/20210115/ea8bbf02c6814a7ba1ba5086a9dc17f9.png,/storage/20210115/ea8bbf02c6814a7ba1ba5086a9dc17f9.png',[],'多图片')
            ->set_up_form('groupselect','分组下拉框','groupselect','6',$array,'分组下拉框',2)
            ->set_up_form('switch','状态','status','0',['开启','关闭'],'开关')
            ->set_up_form('time','时间','time','2021-01-15 00:00:00',[],'我的时间',2)
            ->set_up_form('checkbox','多选框','checkbox','2',$options,'多选框',2)
            ->set_up_form('file','文件框','file','',[],'文件框')
            ->set_up_form('files','多文件框','files','',[],'多文件框')
            ->set_up_form('video','视频文件','video','/storage/20210115/ces.mp4',[],'视频文件')
            ->set_up_form('password','密码域','password','1224556',[],'密码域')
            ->set_up_form('tree','树形','tree','',$tree,'树形')
//            ->set_up_form('linkselect','联动下拉框','shen,shi,qu','',[['id'=>1,'name'=>'四川'],['id'=>2,'name'=>'广州']],'联动下拉框',2,['id'=>'id','show'=>'name'],url('wdeces/index/link')->build())
            ->set_up_form('linkselect','联动下拉框','shen,shi,qu','',['四川','广州'],'联动下拉框',1,['id'=>'id','show'=>'name'],url('wdeces/index/link')->build())
                ->set_up_form('color','颜色选择器','color','')
            ->set_up_form('json','json数组','json',$jsons)
            ->set_button('submit','提交')
            ->fetch();
    }
    public function haha(Request $request){
        $data = $request->param();
//        echo 'jaja';exit;
        $file = $request->file();
//        echo 'jaja';exit;
        $savename = '';
//        var_dump($file);exit;
        if(!empty($file)){
            if(isset($file['img'])){
                $savename = Filesystem::disk('public')->putFile('',$file['img']);
            }
            if(isset($file['imgs'])){
                $savename = Filesystem::disk('public')->putFile('',$file['img']);
            }
        }

        echo '<pre>';
        print_r($data);
        exit;
    }
    public function link(Request $request){
        $data = $request->param();
        if(isset($data['shen'])){
            $array = [
                [
                    'id'=>3,
                    'name'=>'成都'
                ]  ,
                [
                    'id'=>4,
                    'name'=>'资阳'
                ]  ,
            ];
        }elseif (isset($data['shi'])){
            $array = [
                [
                    'id'=>3,
                    'name'=>'乐子'
                ]  ,
                [
                    'id'=>4,
                    'name'=>'生养'
                ]  ,
            ];
        }
        return json_to_respos('请求成功',200,$array);
    }
    public function table(){
        return Quickbuilder::makeTable()
            ->setHeadTool('button','全删除',url('wdeces/index/apis')->build(),'background-color: red')
            ->setHeadTool('a','查看',url('wdeces/index/show')->build(),'background-color:blue')
            ->setAction(url('wdeces/index/get_data')->build())
            ->setPage(true,10)
//            ->setSearch('input','姓名','name')
//            ->setSearch('time','创建时间','name')
//            ->setSearch('select','状态','status',['开启','关闭'])
//            ->setSearch('select','状态s','statuss',[['id'=>1,'name'=>'开启s'],['id'=>0,'name'=>'关闭s']],2)
            ->setColumn('input','ID','id')
            ->setColumn('input','姓名','name')
            ->setColumn('input','电话','phone')
            ->setColumn('input','积分','num')
            ->setTotal(['num'])
            ->setLineButton('button','添加',url('wdeces/index/apis')->build())
            ->setLineButton('a','修改',url('wdeces/index/show?filed=12')->build())
            ->fetch();

    }
    public function apis(Request $request){
        $data = $request->param();
        return json_to_respos('执行成功',200,$data);
    }
    public function show(Request $request){
//        echo 'haha';
        $data = $request->param();
        echo '<pre>';
        print_r($data);
        exit;
    }
    public function get_data(Request $request){
        $name = $request->param('name',null);
        if($name){
            $data= [
                'total'=>1,
                'data'=>[
                    [
                        'id'=>0,
                        'name'=>'你好',
                        'phone'=>'18227948197',
                        'num'=>'1',
                    ],
                    [
                        'id'=>1,
                        'name'=>'你好1',
                        'phone'=>'182279481971',
                        'num'=>'5',
                    ]
                ]
            ];
        }else{
            $data= [
                'total'=>1,
                'data'=>[
                    [
                        'id'=>0,
                        'name'=>'你好',
                        'phone'=>'18227948197',
                        'num'=>'1',
                    ],
//                    [
//                        'id'=>1,
//                        'name'=>'你好1',
//                        'phone'=>'182279481971',
//                        'num'=>'5',
//                    ]
                ]
            ];
        }
        $data= [
            'total'=>1,
            'data'=>[
                [
                    'id'=>0,
                    'name'=>'你好',
                    'phone'=>'18227948197',
                    'num'=>'1',
                ],
                [
                    'id'=>1,
                    'name'=>'你好1',
                    'phone'=>'182279481971',
                    'num'=>'5',
                ]
            ]
        ];
        return json_page_response($data);
    }
}